
/**
 * modal框组件(基于vue3和element-plus)
 * 属性:
 * modalShow:modal框显示隐藏
 * width:modal框宽度
 * footerButtonGroup:modal框底部按钮组显示隐藏
 * headerText:modal框头部标题
 * headerBgColor:modal框头部背景色
 * 方法:
 * cancel:取消,右上角x
 * submit:确定
 * @author gz
 */
<template>
  <div class="gz-model" v-show="modalShow">
    <div
      class="gz-ui"
      :style="{
        width: width + 'px',
      }"
    >
      <div
        class="header"
        :style="{
          backgroundColor: headerBgColor,
        }"
      >
        <h1>{{ headerText }}</h1>
        <span @click="cancel">&times;</span>
      </div>
      <article class="content">
        <slot name="content"></slot>
      </article>
      <div class="footer" v-if="footerButtonGroup">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submit"> 确 定 </el-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    modalShow: {
      type: Boolean,
      default: false
    },
    width: {
      type: Number,
      default: 0
    },
    headerText: {
      type: String,
      default: "新建",
      required: true
    },
    headerBgColor: {
      type: String,
      default: "#fff"
    },
    footerButtonGroup: {
      type: Boolean,
      default: false
    }
  },
  setup(props, ctx) {
    const cancel = () => {
      ctx.emit("cancel");
    };
    const submit = () => {
      ctx.emit("submit");
    };
    return {
      cancel,
      submit
    };
  }
};
</script>

<style scoped>
.gz-model {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10;
}
.gz-ui {
  border: 1px solid #fff;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
}
.header {
  height: 44px;
  padding: 0 15px;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.header h1 {
  display: inline-block;
  font-size: 16px;
  line-height: 44px;
}
.header span {
  color: "#909399";
  cursor: pointer;
}
.content {
  padding: 15px;
}
.footer {
  text-align: right;
  padding: 15px;
  border-top: 1px solid #c0c4cc;
}
</style>